import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:news/com.comm/model/notify.dart';
import 'package:news/com.comm/widget/empty_egwidget.dart';

/// 通用控件整理  (常用功能代码块集合 减少代码量)
/// author  gxj
/// date   2020.6.1

///返回text 组件
Widget getTextWidget(double textSize, String text, Color textColor,
    {FontWeight? fontWeight,
    TextDecoration? decoration,
    TextOverflow? overflow,
    Key? key,
    int? maxLines,
    double? height,
    TextAlign textAlign = TextAlign.left}) {
  return Text(
    text,
    key: key,
    textAlign: textAlign,
    overflow: overflow,
    maxLines: maxLines,
    style: TextStyle(
        decoration: decoration,
        color: textColor,
        fontSize: textSize,
        fontWeight: fontWeight,
        height: height),
  );
}

///返回价格 组件
Widget getPriceWidget(double textSize, double price, Color textColor,
    {double? dollarFontSize}) {
  String priceLeft;
  String priceRight;
  if (price == null) {
    priceLeft = "00";
    priceRight = "00";
  } else {
    if (price.toString().contains(".")) {
      List priceS = price.toStringAsFixed(2).split(".");
      priceLeft = priceS[0];
      priceRight = priceS[1];
    } else {
      priceLeft = price.toString();
      priceRight = "00";
    }
  }
  return Container(
      child: Text.rich(
    TextSpan(children: [
      TextSpan(
        text: '￥',
        style: TextStyle(
            color: textColor == null ?  Color(0xF43333) : textColor,
            fontSize: dollarFontSize != null && dollarFontSize > 0
                ? dollarFontSize
                : textSize - 4,
            fontWeight: FontWeight.w500),
      ),
      TextSpan(
        text: priceLeft,
        style: TextStyle(
            color: textColor == null ?  Color(0xF43333) : textColor,
            fontSize: textSize,
            fontWeight: FontWeight.w500),
      ),
      TextSpan(
        text: "." + priceRight,
        style: TextStyle(
            color: textColor == null ? Color(0xffF43333) : textColor,
            fontSize: dollarFontSize != null && dollarFontSize > 0
                ? dollarFontSize
                : textSize - 4,
            fontWeight: FontWeight.w500),
      )
    ]),
  ));
}

///获取圆角容器Container
Widget getRadiusContainer(Color color, double radius,
    {double? width,
    double? height,
    Widget? child,
    EdgeInsets? margin,
    Alignment? alignment,
    EdgeInsets? padding}) {
  return Container(
      height: height,
      width: width,
      child: child,
      margin: margin,
      padding: padding,
      alignment: alignment == null ? Alignment.center : alignment,
      decoration: BoxDecoration(
          color: color,
          borderRadius: BorderRadius.all(Radius.circular(radius))));
}

///获取圆角容器 (有阴影/背景图片 )Container
Widget getShadowRadiusContainer(Color color, double radius,
    {double width=0.0,
    double height=0.0,
    required Widget child,
    EdgeInsets? margin,
    AssetImage? img}) {
  return Container(
      height: height,
      width: width,
      child: child,
      margin: margin,
      alignment: Alignment.center,
      decoration: BoxDecoration(
          color: img != null ? null : color,
          image: DecorationImage(
            image: img!,
            fit: BoxFit.cover,
          ),
          boxShadow: [
            BoxShadow(
              color: Color(0xffD8D8D8),
              spreadRadius: 5.0,
              offset: Offset(3.0, 3.0),
            ),
          ],
          borderRadius: BorderRadius.all(Radius.circular(radius))));
}

///返回订单列表 失效遮罩层
Widget getShapeView(bool isVisible, String failText) {
  return Visibility(
      visible: isVisible,
      child: Stack(alignment: Alignment.center, children: <Widget>[
        Container(
          width: 100,
          height: 100,
          decoration: BoxDecoration(
              color: Color(0x99ffffff),
              borderRadius: BorderRadius.all(Radius.circular(4))),
          alignment: Alignment.center,
        ),
        Container(
          width: 60,
          height: 60,
          decoration: BoxDecoration(
              color: Color(0x80000000),
              borderRadius: BorderRadius.all(Radius.circular(30))),
          alignment: Alignment.center,
        ),
        Container(
            width: 52,
            height: 52,
            alignment: Alignment.center,
            decoration: BoxDecoration(
                border: Border.all(width: 0.5, color: Color(0xffffffff)),
                borderRadius: BorderRadius.all(Radius.circular(26)))),
        Container(
            width: 26,
            child: Text(
              failText,
              style: TextStyle(color: Colors.white, fontSize: 12),
              softWrap: true,
              maxLines: 2,
            ))
      ]));
}

/// 暂无商品缺省页面
Widget getNoDataPage({String? text}) {
  return Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Image.asset('assets/images/payattention_image.png',
            width: 185.0, height: 119.0, fit: BoxFit.contain),
        SizedBox(height: 8.0),
        Text(text == null ? '暂无商品' : text,
            textScaleFactor: 1.0,
            style: TextStyle(fontSize: 14.0, color: Color(0xff999999)))
      ],
    ),
  );
}
//
// /// 暂无数据缺省界面
// Widget loadingAnimateNew(bool isNetworkError, Function callBack) {
//   return Center(
//       child: isNetworkError == true
//           ? EmptyEGWidget(
//               emptyMsg: '网络异常',
//               imageUrl: "assets/images/net_err.png",
//               btnMsg: "点击刷新",
//               isHideButton: false,
//               onClick: () {
//                 callBack();
//               },
//             )
//           : RefreshIndicator(
//               onRefresh: () {
//                 return Future.delayed(Duration(milliseconds: 600), () {
//                   callBack();
//                 });
//               },
//               child: Container(
//                   color: Colors.white,
//                   child: ListView(physics: AlwaysScrollableScrollPhysics(),
//                       // primary: true,
//                       children: [
//                         Container(height: 600, child: PlaceholderWidget(() {}))
//                       ]))));
// }

Widget _buildMaterialDialogTransitions(
    BuildContext context,
    Animation<double> animation,
    Animation<double> secondaryAnimation,
    Widget child) {
  return FadeTransition(
    opacity: CurvedAnimation(
      parent: animation,
      curve: Curves.easeOut,
    ),
    child: child,
  );
}

// 售后详情复制按钮
Widget getClipboard(BuildContext context, String text) {
  return GestureDetector(
    onTap: () {
        // NotifyManager.showInfo(context, '复制成功');
      Clipboard.setData(
        ClipboardData(
          text: '$text',
        ),
      );
      NotifyManager.showInfo(context, '复制成功');
    },
    child: Container(
      width: 36,
      height: 18,
      margin: EdgeInsets.only(left: 12),
      alignment: Alignment.center,
      decoration: BoxDecoration(
          color: Color(0xFFF3F2F5), borderRadius: BorderRadius.circular(12)),
      child: Text(
        '复制',
        style: TextStyle(fontSize: 10, color: Color(0xff333333)),
      ),
    ),
  );
}
